#include "verilated_dpi.h"
#include <cpu/cpu.h>
#define word_t uint64_t

extern uint64_t *cpu_gpr; 

extern "C" void set_gpr_ptr(const svOpenArrayHandle r) {
	  cpu_gpr = (uint64_t *)(((VerilatedDpiOpenVar*)r)->datap());
	  for (int i = 0 ; i<32;i++) 
		  cpu.gpr[i] = cpu_gpr[i];
}


const char *regs[] = {
  "$0", "ra", "sp", "gp", "tp", "t0", "t1", "t2",
  "s0", "s1", "a0", "a1", "a2", "a3", "a4", "a5",
  "a6", "a7", "s2", "s3", "s4", "s5", "s6", "s7",
  "s8", "s9", "s10", "s11", "t3", "t4", "t5", "t6"
};

void isa_reg_display() {
	int i;
	for(i=0;i<31;i+=1)
	{
		printf(" No:%d,Regname:%s value:0x%016lx \n",i,regs[i],cpu_gpr[i]);
	}
}

word_t isa_reg_str2val(const char *s, bool *success) {
word_t regvalue = 0;
*success = false;

for(int i=0;i<31;i+=1){
	 if(!strcmp(s,regs[i])){
	 	regvalue = cpu_gpr[i];
//		printf("find!\n");
		*success = true;
	 }
	}
/*	if(!strcmp(s,"pc")){
		regvalue = cpu.pc;
		*success = true;
	}*/
	 if(!*success) {
		 printf("Wrong Reg name, please enter right reg name\n");
		assert(0);
	 }
return regvalue;
 }
